package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.product.pojo.dto.FilterAttrOnOffJXCDTO;
import com.xbongbong.pro.product.pojo.vo.FilterAttrOnOffJXCVO;
import com.xbongbong.saas.domain.entity.ContractProductEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.domain.entity.ext.RefundEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import org.apache.ibatis.annotations.Param;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/3/22 16:44
 * @since v1.0
 */
public interface RefundModel extends IModel<RefundEntityExt> {
    /**
     * 退货退款单数据单条查询
     *
     * @param key    主键ID
     * @param corpid 公司ID
     * @return Integer
     * @author feng.zheng
     * @date 2019/2/15 20:27
     * @since v1.0
     */
    RefundEntityExt getByKey(Long key, String corpid);

    Integer update(RefundEntityExt refundEntityExt, boolean isSaveSub) throws XbbException;

    /**
     * 查找
     *
     * @param param 查询条件
     * @return 实体集合
     */
    @Override
    List<RefundEntityExt> findEntitys(@Param("param") Map<String, Object> param);

    /**
     * 保存
     *
     * @param refundEntityExt 退货退款单实体
     * @return Integer
     * @author feng.zheng
     * @date 2019/1/23 20:27
     * @since v1.0
     */
    Integer save(RefundEntityExt refundEntityExt) throws XbbException;

    Integer save(RefundEntityExt refundEntityExt, boolean isSaveSub) throws XbbException;

    /**
     * 批量删除
     *
     * @param idList 数据id列表
     * @param corpid 公司id
     * @param del    删除标识
     * @throws XbbException 异常
     */
    Integer deleteBatch(List<Long> idList, String corpid, Integer del) throws XbbException;

    /**
     * 批量更新
     *
     * @param list   数据列表 格式：[{"corpid": "", "id": "", "data":[{"key": "", "value": ""}]}]
     * @param corpid 公司id
     * @return Integer
     * @throws XbbException XbbException
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid) throws XbbException;

    /**
     * 批量更新
     *
     * @param list   数据列表 格式：[{"corpid": "", "id": "", "data":[{"key": "", "value": ""}]}]
     * @param corpid 公司id
     * @return Integer
     * @throws XbbException XbbException
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid,boolean needThrow) throws XbbException;

    Integer updateBatchImmediately(List<UpdateDataEntity> list, String corpid) throws XbbException;

    /**
     * 删除
     *
     * @param key    主键
     * @param corpid 公司id
     * @return 是u否成
     * @throws XbbException 异常
     */
    Integer deleteByKey(Long key, String corpid) throws XbbException;

    List<String> getCorpids() throws XbbException;

    @Override
    List<RefundEntityExt> findEntitysWithoutSub(Map<String, Object> param);

    Integer deleteByKey4Process(Long key, String corpid) throws XbbException;

    FilterAttrOnOffJXCVO filterAttrOnOffJXC(FilterAttrOnOffJXCDTO filterAttrOnOffJXCDTO) throws XbbException;

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 编辑时将获取数据格式化
     *
     * @param saasAnalysisDataDTO saas编辑数据
     * @param result              要返回的jsonobject
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/22 15:28
     */
    void formatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    void getProductList(String corpid, List<ContractProductEntity> conProductList, JSONArray productArray, Map<Long, ProductEntityExt> productMap) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    /**
     * 编辑格式化数据格式
     *
     * @param saasAnalysisDataDTO saas编辑数据
     * @throws XbbException 参数格式错误异常
     * @param result 要返回的jsonobject
     * @author chaoxiong.lei
     * @date 19:08 2019/1/20
     * @since v1.0
     **/
    void formatDataForDistributor(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    Integer updateTime(Long id,String corpid) throws XbbException ;
}
